Skip to content

feat(datetime): add shadow parts and CSS variables for styling wheel pickers #27529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 6, 2023

Conversation

averyjohnston
Copy link
Contributor

@averyjohnston averyjohnston commented May 22, 2023

Issue number: resolves #25945


What is the current behavior?

Datetime wheel pickers cannot be styled.

What is the new behavior?

Adds styling APIs in accordance with the Wheel Pickers and Time Picker sections of this design doc.

Shadow parts added:

  • wheel-item
  • wheel-item active
  • time-button
  • time-button active

CSS properties added:

  • --wheel-highlight-background
  • --wheel-fade-background-rgb

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.0.7-dev.11685554390.10c2ca9b
Docs PR: ionic-team/ionic-docs#2982

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label May 22, 2023
*
* @part picker-item - The individual items when using a wheel style layout, or in the
* month/year picker when using a grid style layout.
* @part picker-item active - The currently selected picker-item.
Copy link
Contributor Author

@averyjohnston averyjohnston May 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't just do @part active here since that part also applies to the time button and may include others down the road, so I went with this since it's how the usage code will look (e.g. ::part(picker-item active)).

I'm open to changing the active part name to picker-item-active instead. The W3C guidelines imply that state-based shadow parts should be non-specific (i.e. it should be part="picker-item active" and not part="picker-item picker-item-active") but doing it that way does lead to somewhat awkward documentation.

Same general idea goes for changing the time button part to time-button-active.

Comment on lines 36 to 40
/*
The second selectors that target ion-picker(-column)-internal
directly are for styling the time picker. This is currently
undocumented usage.
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note to update this in the design doc for making the internal picker public: https://ionic-cloud.atlassian.net/browse/FW-4401

@averyjohnston averyjohnston marked this pull request as ready for review May 23, 2023 18:26
}

:host .picker-highlight {
background: var(--ion-color-step-150, #eeeeef);
background: var(--picker-highlight-background, var(--ion-color-step-150, #eeeeef));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be set on the :host:

:host {
  --picker-highlight-background: var(--ion-color-step-150, #eeeeef);
}

That way you don't need to re-set the background property.

Copy link
Contributor Author

@averyjohnston averyjohnston May 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it that way causes the default iOS color to overwrite a custom color applied through ion-datetime. You can only apply it directly to ion-picker-internal when styling the time picker due to shadow nesting, so other things (wheel style datetimes and the month/year picker) don't get styled.

Or in other words, this no longer works:

ion-datetime {
  --picker-highlight-background: pink;
}

@averyjohnston averyjohnston requested a review from liamdebeasi May 24, 2023 18:29
@averyjohnston averyjohnston requested a review from liamdebeasi May 25, 2023 19:25
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality works great!

core/api.txt Outdated
Comment on lines 427 to 431
ion-datetime,css-prop,--picker-fade-background-rgb
ion-datetime,css-prop,--picker-highlight-background
ion-datetime,css-prop,--title-color
ion-datetime,part,picker-item
ion-datetime,part,picker-item active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshed: Can we use wheel terminology instead of picker to be consistent with the preferWheel property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me 👍

@averyjohnston averyjohnston requested a review from liamdebeasi May 30, 2023 19:04
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@averyjohnston averyjohnston merged commit f2c1845 into feature-7.1 Jun 6, 2023
@averyjohnston averyjohnston deleted the FW-2254 branch June 6, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants